package com.itheima.qingcheng.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.qingcheng.anno.Log;
import com.itheima.qingcheng.mapper.BrandMapper;
import com.itheima.qingcheng.pojo.Brand;
import com.itheima.qingcheng.pojo.BrandQuery;
import com.itheima.qingcheng.pojo.PageBean;
import com.itheima.qingcheng.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zhangzhen
 * @version 1.0
 * @date 2025/1/21 9:26
 */
@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private  BrandMapper brandMapper;
    @Override
    public PageBean findPage(Integer pageSize, Integer size, BrandQuery brandQuery) {
        PageHelper.startPage(pageSize, size);
        Page<Brand> page= brandMapper.findPage(brandQuery);
        return new PageBean(page.getTotal(),page.getResult());
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public void add(Brand brand) {
        brandMapper.insert(brand);
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public void updateById(Brand brand) {
        brandMapper.update(brand);
    }


    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public void deleteById(Integer id) {
        brandMapper.deleteById(id);
    }

    @Override
    public Brand selectById(Integer id) {
       Brand brand= brandMapper.selectById(id);
        return  brand;
    }
}